// TypeScript file
class PromptPop extends egret.Sprite
{
    public targetMc: StarlingSwfMovieClip;
    private isShow: boolean = false;
    private isInto: boolean = false;
    private isAway: boolean = false;
    private isHide:boolean = false;
    private stay:number = 0;
    private tx: number = 0;
    private ty: number = 0;
    private tw: egret.Tween;

    public config: Object = 
    {
        "isHide" : true,
        "stayTime": 800,
        "tx": 0,
        "ty": 0
    };
    constructor()
    {
        super();
    }

    public activate(tx: number=0, ty: number=0, configType: Object = null): void
    {
        this.config["tx"] = tx;
        this.config["ty"] = ty;
        this.settings(configType);

        this.targetMc = StarlingSwfFactory.getInstance().makeMc("tip");
        this.addChild(this.targetMc);
        this.targetMc.x = this.tx;
        this.targetMc.y = this.ty;
        this.targetMc.visible = false;
    }

    public show(idx: string, tweenType: Object = null): void
    {
        if (null == this.targetMc) return;

        if (null == idx) return;

        if (tweenType != null)
        {
            let key: string = "isHide";
            if (tweenType[key] != null) this.isHide = tweenType[key];
            key = "stayTime";
            if (tweenType[key] != null) this.stay = tweenType[key];
            key = "tx";
            if (tweenType[key] != null) this.tx = tweenType[key];
            key = "ty";
            if (tweenType[key] != null) this.ty = tweenType[key];
        }
        this.setMc(idx);
        this.tweenStar();
    }

    private tweenStar(): void
    {
        this.isInto = true;
        this.isShow = true;
        this.isAway = false;

        let target: StarlingSwfMovieClip = this.targetMc;
        target.x = this.tx;
        target.y = this.ty;
        target.alpha = 1;
        target.visible = true;
        this.tw = egret.Tween.get(target).call(this.tweenStop, this);
        this.tw.to({y:this.ty - 200, alpha:1}, 200);
    }

    private tweenStop(): void
    {
        this.isInto = false;
        if (this.isHide)
        {
            this.isAway = true;
            this.tw = egret.Tween.get(this.targetMc).call(this.tweenOver, this);
            this.tw.to({alpha:0, delay:1, visible:false}, this.stay);
        }
        this.settings();
    }

    private tweenOver(): void
    {
        this.isShow = false;
        this.isAway = false;
    }

    public hide(delay: number = 0): void
    {
        this.isHide = true;
        this.stay = delay;
        this.tweenStop();

    }

    public settings(configType: Object = null): void
    {
        if (configType != null)
        {
            for (let c in this.config)
            {
                this.config[c] = configType[c] != null ? configType[c] : this.config[c];
            }
        }

        this.isHide = this.config["isHide"];
        this.stay = this.config["stayTime"];
        this.tx = this.config["tx"];
        this.ty = this.config["ty"];
    }

    private setMc(idx: string): void
    {
        this.targetMc.goToPlay(idx);

    }

    public get isSHOW(): boolean
    {
        return this.isShow;
    }

    public get isINTO(): boolean
    {
        return this.isInto;
    }

    public get isAWAY(): boolean
    {
        return this.isAway;
    }

    public removeAll(): void
    {

    }
    
}